package com.antong.cloud.common.core.util;

import lombok.*;

/**
 * 响应消息主体
 */
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class R<T> {

    /**
     * 成功标记
     */
    public static final String SUCCESS_STATE = "SUCCESS";

    /**
     * 失败标记
     */
    public static final String FAIL_STATE = "FAIL";

    @Getter
    @Setter
    private String state;

    @Getter
    @Setter
    private String message;

    @Getter
    @Setter
    private T data;

    public static <T> R<T> ok(){
        return new R<>(SUCCESS_STATE, null, null);
    }

    public static <T> R<T> ok(T data){
        return new R<>(SUCCESS_STATE, null, data);
    }

    public static <T> R<T> ok(T data, String message){
        return new R<>(SUCCESS_STATE, message, data);
    }


    public static <T> R<T> fail(){
        return new R<>(FAIL_STATE, null, null);
    }

    public static <T> R<T> fail(T data){
        return new R<>(FAIL_STATE, null, data);
    }

    public static <T> R<T> fail(T data, String message){
        return new R<>(FAIL_STATE, message, data);
    }

}
